<?php 
	/**
	 * 每天删除30天以前的数据
	 */

	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	
	//$today = date('Y-m-d',time()-24*60*60);
	$today = date('Y-m-d');
	$global_site = "tools";
	//处理抓取的页面
	$compeitior = array('baihe','zhenai','yuanlai','youyuan');
	//$compeitior = array('baihe','zhenai','yuanlai');
	//$compeitior = array('youyuan');
	foreach($compeitior as $key=>$value){
		$file = ROOT_PATH."/".$value."/log/register_log/$today.log";
		if (is_file($file) && $lines = file($file)) {
			$last = count($lines)-1;
			$line = $lines[$last];
			$arr = explode("\t", $line);
			//echo $arr[0];
			isset($arr[0]) && $time = strtotime($arr[0]);
			if ((time()-$time)>3600) {
				$subject = '竞争对手'.$value.'注册脚本异常';
				$content = '竞争对手'.$value.'注册脚本在'.date('Y-m-d H:i:s').'检测出现异常，'."<br>最后一条数据为：".$line."<br>机器将重启！"."<br>";
				
				sendMailEx($subject, $content);
				$hour = date('H');
				//echo '--------'.$hour;
				if ($hour > 14) {//防止正在抓取的时候重启
					system("D:\competitor\process\dial.bat");
					sleep(10);
					$command = "D:\competitor\process\\".$value."_register.bat";
					system($command);
					sleep(10);
					echo 'reboot';
					
					reboot();
					exit;
				}
			}
		}
	}
	echo 'check ok';
	function reboot()
	{
		system('C:\Windows\System32\shutdown.exe -r');
	}
?>